-- Aware 1.0, re-code of the original addon for the 4.x versions of World of Warcraft.
-- This addon is from now on maintained and coded by Aevitas, based on the original work of Videa and Griggs.

function Aware_OnLoad(this) -- Constructor
	this:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
	print("Aware 1.0 - Aevitas Recode loaded.")
end

local Enabled = 1	 	-- Do we want Aware to track stuff?
local Debug				-- Debug mode. Should not be touched by mere mortals.

-- Aware Spell List, contains a "dictionary" of spells and their respective ID's.
-- Revision 1 (Aevitas) - Client 4.0.6, 24/02/2010

local S = {} -- Whoa! Hostile spells!
local B = {} -- Buff spells.

-- Buffs and stuff we want to be notified of.
B[1044] = "Hand of Freedom"
B[1038] = "Hand of Salvation"

-- Player hostile spells
S[46924] = "Bladestorm"
S[77606] = "Dark Simulacrum"
S[31224] = "Cloak of Shadows"
S[47585] = "Dispersion"
S[23920] = "Spell Reflection"
S[48707] = "Anti Magic Shell"
S[45438] = "Ice Block"
S[49039] = "Lichborne"
S[50334] = "Berserk (Feral)"
S[18499] = "Berserker Rage"
S[59672] = "Metamorphosis"
S[31687] = "Summon Water Elemental"
S[34692] = "The Beast Within"
S[6346] = "Fear Ward"
S[19263] = "Deterrence"

-- End Spell List

-- Aware: Main Event Handler. This occurs when the COMBAT LOG even pops. (That is often!)
-- Aevitas: Currently looking into making this somewhat more efficient in terms of how often it fires. Maybe use my HookLib?
function Aware_OnEvent(self, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13) -- Aevitas: Bugfix; register the event handler, and invoke parameters.

if (Enabled ~= 1) then return end -- Are we even meant to be running?

-- Aevitas: Note that functionality of beneficial spells is currently limited to Freedom and Salvation.

if (arg2 == "SPELL_CAST_SUCCESS") then
	if bit.band(arg8, COMBATLOG_OBJECT_AFFILIATION_MINE) > 0 then
		if (B[arg9] ~= "") then -- arg9 = spellID, arg10 = spellName
			-- Dumping our messaging to the ZoneText frame by default. For now.
			-- Henkz: Perhaps display unit names as well?
			ZoneTextString:SetText(arg10.." active.");
			
			-- Set the frame stuff so we don't end up with the text in our screens forever.
			ZoneTextFrame.startTime = GetTime(); 	-- The current time.
			ZoneTextFrame.fadeInTime = 0
			ZoneTextFrame.holdTime = 1 				-- Hold it for a second.
			ZoneTextFrame.fadeOutTime = 2
			ZoneTextString:SetTextColor(0, 1, 0);	--- R,G,B - Green.
			PVPInfoTextString:SetText("");
			ZoneTextFrame:Show()
			
		end -- End arg9
	end -- End bit.band
end -- End arg2

--- Hostile spell cast.

if (arg2 == "SPELL_CAST_SUCCESS") then
	if bit.band(arg5, COMBATLOG_OBJECT_REACTION_HOSTILE) > 0 then -- Make sure the unit is hostile.
		if (S[arg9] ~= "") then -- Does out spell dictionary contain this entry?
		
			ZoneTextString:SetText(arg10.." active.");
			
			-- Set the frame stuff so we don't end up with the text in our screens forever.
			ZoneTextFrame.startTime = GetTime(); 	-- The current time.
			ZoneTextFrame.fadeInTime = 0
			ZoneTextFrame.holdTime = 1 				-- Hold it for a second.
			ZoneTextFrame.fadeOutTime = 2
			ZoneTextString:SetTextColor(1, 0, 0);	--- R,G,B - Green.
			PVPInfoTextString:SetText("");
			ZoneTextFrame:Show()
		end -- End arg9
	end -- End bit.band
end -- End arg2

--- Hostile spell fade.

if (arg2 == "SPELL_AURA_REMOVED") then
	if bit.band(arg8, COMBATLOG_OBJECT_REACTION_HOSTILE) > 0 then
		if (S[arg9] ~= "") then -- We're tracking this spell!
		
			ZoneTextString:SetText(arg10.." faded!");
			
			-- Set the frame stuff so we don't end up with the text in our screens forever.
			ZoneTextFrame.startTime = GetTime(); 	-- The current time.
			ZoneTextFrame.fadeInTime = 0
			ZoneTextFrame.holdTime = 1 				-- Hold it for a second.
			ZoneTextFrame.fadeOutTime = 2
			ZoneTextString:SetTextColor(0, 0, 1);	--- R,G,B - Green.
			PVPInfoTextString:SetText("");
			ZoneTextFrame:Show()
		end -- End arg9
	end -- End bit.band
end -- End arg2
		

end -- End Aware_OnEvent(params)

SLASH_AWARE1 = "/aware"
SlashCmdList["AWARE"] = function(msg)
	if (Enabled == 1) 
		then Enabled = 0 
		print("Aware is now disabled.")
	else 
		Enabled = 1 
		print("Aware is now enabled.")
	end
	
end